﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DBLOG.BizTalk.BizTalkExplorerServices.Core;
using DBLOG.BizTalk.BizTalkExplorerServices.Entities;

namespace DBLOG.BizTalk.BizTalkExplorerServices.Explorers
{
    public class SummaryExplorer : BizTalkExplorerBase
    {
        private BTSSummary _btsSummary { get; set; }

        public BTSSummary GetSummary()
        {
            _btsSummary = new BTSSummary();

            this.GetSimpleValues();
            this.GetErrors();
            this.GetWarnings();
            this.GetMessagesInProcess();

            return _btsSummary;
        }

        private void GetSimpleValues()
        {
            _btsSummary.ServerName = BizTalkSettings.ServerName;
            _btsSummary.CountApplications = this._explorer.Applications.Count;
            _btsSummary.CountHosts = this._explorer.Hosts.Count;
            _btsSummary.CountSendPorts = this._explorer.SendPorts.Count;
            _btsSummary.CountReceivePorts = this._explorer.ReceivePorts.Count;
        }

        private void GetErrors()
        {
            using (ErrorExplorer errorExplorer = new ErrorExplorer())
            {
                _btsSummary.CountErrors = errorExplorer.GetErrors().Count;
            }
        }

        private void GetWarnings()
        {
            using (WarningExplorer warningExplorer = new WarningExplorer())
            {
                _btsSummary.CountWarnings = warningExplorer.GetWarnings().Count;
            }
        }

        private void GetMessagesInProcess()
        {
            using (MessageExplorer messageExplorer = new MessageExplorer())
            {
                _btsSummary.CountMessagesInProcess = messageExplorer.GetMessages().Count;
            }
        }

    }
}